package edu.strategy.single.scanned;

import robocode.AdvancedRobot;
import robocode.Event;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;
import edu.strategy.single.Single;

public class CaligulaFirstModScannedStrategy extends Single{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static double enemyEnergy = 0;
	static double dir;
	static int mode = 3;
	public CaligulaFirstModScannedStrategy(AdvancedRobot advancedRobot) {
		super(advancedRobot);
	}
	
	@Override
	public void prepare() {
		dir=.002;
	}


	@Override
	public void work() {
		super.getAdvancedRobot().fire(1);
	}

	@Override
	public void work(Event e) {
		super.used();
		ScannedRobotEvent srv = (ScannedRobotEvent) e;
		
		double absBearing;
		double latVel;
		double eBearing;
		super.getAdvancedRobot().setTurnRightRadians(Math.cos(eBearing=absBearing=srv.getBearingRadians())+dir*(160-(latVel=srv.getDistance())));
		super.getAdvancedRobot().setFire(latVel<150?3:2);
		super.getAdvancedRobot().setTurnRadarLeftRadians(super.getAdvancedRobot().getRadarTurnRemainingRadians());
		if(enemyEnergy>(enemyEnergy=srv.getEnergy())&&mode>=2){
			dir=-dir;
		}
		super.getAdvancedRobot().setAhead(dir*Double.POSITIVE_INFINITY);
		super.getAdvancedRobot().setTurnGunRightRadians(Utils.normalRelativeAngle((absBearing+=super.getAdvancedRobot().getHeadingRadians())-super.getAdvancedRobot().getGunHeadingRadians())+
				Math.random()*(latVel=srv.getVelocity()*Math.sin(srv.getHeadingRadians()-absBearing))/14);
	}

	@Override
	public String toString() {
		return "CaligulaFirstModScannedStrategy";
	}

}
